local extension  = Package:new("sifu_heg_tyta")
extension.extensionName = "sifu_heg"
extension.game_modes_whitelist = {"zhonger_heg_mode"}

local H = require "packages/ol_hegemony/util"
local U = require "packages/utility/utility"
local S = require "packages/sifu_heg/SeaFunc"
local ZR = require "packages/ol_hegemony/umark"
Fk:loadTranslationTable{
    ["sifu_heg_tyta"] = "线下专属",
    ["tyta_heg"] = "线下"
  }
local wangling = General(extension,"tyta_heg__wangling","wei",4)--王凌
local mouli = fk.CreateViewAsSkill{
  name = "tyta_mouli",
  anim_type = "special",
  pattern = ".",
  prompt = "#tyheg__mibei-prompt",
  interaction = function(self)
    local cids = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0 and (Fk:getCardById(id):isCommonTrick() or Fk:getCardById(id).type == Card.TypeBasic) 
      and  Fk:getCardById(id).trueName ~= "threaten_emperor"
    end)
    local cards  = table.map(cids, function(id)
      return Fk:getCardById(id).name 
    end)
    return UI.ComboBox {
      choices = cards
    }
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select):getMark("@@mibei_cardMark-inhand") ~= 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0
    end) and player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0
    end) and player:usedSkillTimes(self.name) == 0
  end,
}
local mibei  = fk.CreateTriggerSkill{
  name = "tyta_mibei",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and not table.every(player.room:getOtherPlayers(player), function(p)
      return #player:getCardIds("h") >= #p:getCardIds("h")
    end) 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p1)
      return table.every(player.room:getOtherPlayers(player), function(p2)
        return #p1:getCardIds("h") >= #p2:getCardIds("h")
      end)
    end)
    targets = table.map(targets, Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#tyheg__mibei-invoke", self.name, true)
    if #to > 0 then
      self.cost_data = to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    player:broadcastSkillInvoke("tyta_mibei", table.random({1, 2}))
    local isDoCommand = H.askCommandTo(to, player, self.name)
    if isDoCommand then
      local num = math.min(5, #to:getCardIds("h") - #player:getCardIds("h"))
      if num > 0 then
        player:drawCards(num, self.name)
      end
    else
      local cards = room:askForCard(player, 1, 3, false, self.name, true, ".", "#tyheg__mibei-choose")
      if #cards > 0 then
        player:broadcastSkillInvoke("tyta_mibei", table.random({1, 2}))
        room:addPlayerMark(player,"@@mibei_check",1)
        player:showCards(cards)
        for _, id in ipairs(cards) do
          local c = Fk:getCardById(id)
          room:setCardMark(c, "@@mibei_cardMark-inhand", 1)
        end
      end
    end
  end,
}
local mibei_lost = fk.CreateTriggerSkill{
  name="#mibei_lost",
  events = {fk.TurnEnd},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("tyta_mibei")  and target ==player and player:getMark("@@mibei_check") ~=0
  end,
  on_use = function (self, event, target, player, data)
    local room =player.room
    local cards = player.player_cards[Player.Hand]
    for _, id in ipairs(cards) do
      local c = Fk:getCardById(id)
    room:removeCardMark(c,"@@mibei_cardMark-inhand",1)
    room:removePlayerMark(player,"@@mibei_check",1)
    end
  end,

}
wangling:addSkill(mibei)
mibei:addRelatedSkill(mibei_lost)
wangling:addSkill(mouli)
Fk:loadTranslationTable{
  ["tyta_heg__wangling"] = "王凌",
  ["#tyta_heg__wangling"] = "深谋远虑",
  ["tyta_mouli"] = "谋立",
  [":tyta_mouli"] = "出牌阶段限一次，你可将一张“秘备”牌当其中一张基本牌或普通锦囊牌使用。(【挟天子以令诸侯】除外)",
  ["tyta_mibei"] = "秘备",
  [":tyta_mibei"] = "准备阶段，若你的手牌数不为场上最多，你选择场上手牌数最多的一名角色，该角色令你执行一次“军令”；若你执行，你将手牌摸至X张(X为军令发起者的手牌数，至多摸5张)；若你不执行，你展示一至三张手牌并增加“秘备”标记。"..
  "回合结束时，你移除所有“秘备”标记。",
  ["#tyheg__mibei-invoke"] = "秘备：你可以选择一名角色，发动“秘备”",
  ["@@mibei_cardMark-inhand"] = "秘备",
  ["#mibei_lost"]="秘备",
  ["#tyheg__mibei-prompt"] = "秘备：你可以将一张“秘备”牌当其中一张牌使用",
  ["#tyheg__mibei-choose"] = "秘备：你可以选择展示一至三张手牌",
  ["@@mibei_check"]="秘备手牌",
  ["$tyta_mouli1"] = "司马氏虽权尊势重，吾等徐图亦无不可！",
  ["$tyta_mouli2"] = "先谋后事者昌，先事后谋者亡！",
  ["$tyta_mibei1"] = "密为之备，不可有失。",
  ["$tyta_mibei2"] = "事以密成，语以泄败！",
  ["~tyta_heg__wangling"] = "一生尽忠事魏，不料今日晚节尽毁啊！",
}
local lifeng = General (extension,"tyta_heg__lifeng","shu",3) --李丰
local tunchu = fk.CreateTriggerSkill{
  name = "tyta_tunchu",
  anim_type = "drawcard",
  derived_piles = "tylifeng_liang",
  events = {fk.DrawNCards, fk.AfterDrawNCards},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.DrawNCards then
        return player:hasSkill(self) 
      else
        return player:usedSkillTimes(self.name, Player.HistoryPhase) > 0 and not player:isKongcheng()
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local cards = player.room:askForCard(player, 1, 2, false, self.name, false, ".", "#ty_tunchu-put")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      data.n = data.n + 2
      player.room:setPlayerMark(player, "@@ty_tunchu_prohibit-turn", 1)
    else
      player:addToPile("tylifeng_liang", self.cost_data, true, self.name)
    end
  end,
}
local tunchu_prohibit = fk.CreateProhibitSkill{
  name = "#ty_tunchu_prohibit",
  prohibit_use = function(self, player, card)
    return player:hasSkill(tunchu) and player:getMark("@@ty_tunchu_prohibit-turn") > 0 and card.trueName == "slash"
  end,
}
local shuliang = fk.CreateTriggerSkill{
  name = "tyta_shuliang",
  anim_type = "support",
  expand_pile = "tylifeng_liang",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and (target == player or (H.compareKingdomWith(target, player) and player:distanceTo(target) <= #(player:getPile("tylifeng_liang") or {}))) and
    #player:getPile("tylifeng_liang") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true,
      ".|.|.|tylifeng_liang|.|.", "#ty_shuliang-invoke::"..target.id, "tylifeng_liang")
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:moveCards({
      from = player.id,
      ids = self.cost_data,
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonPutIntoDiscardPile,
      skillName = self.name,
      specialName = self.name,
    })
    if not target.dead then
      target:drawCards(2, self.name)
    end
  end,
}
tunchu:addRelatedSkill(tunchu_prohibit)
lifeng:addSkill(tunchu)
lifeng:addSkill(shuliang)
Fk:loadTranslationTable{
  ["tyta_heg__lifeng"] = "李丰",
  ["#tyta_heg__lifeng"] = "朱提太守",
  ["cv:tyta_heg__lifeng"] = "秦且歌",
  ["illustrator:tyta_heg__lifeng"] = "NOVART",
  ["tyta_tunchu"] = "屯储",
  [":tyta_tunchu"] = "摸牌阶段，你可以多摸两张牌，然后将至多两张手牌置于你的武将牌上，称为“粮”；然后本回合你不能使用【杀】。",
  ["tyta_shuliang"] = "输粮",
  [":tyta_shuliang"] = "一名与你势力相同角色的结束阶段，若你与其距离不大于“粮”数，你可以移去一张“粮”，然后该角色摸两张牌。",
  ["tylifeng_liang"] = "粮",
  ["@@ty_tunchu_prohibit-turn"] = "屯储",
  ["#ty_tunchu-put"] = "屯储：你可以将至多两张手牌置为“粮”",
  ["#ty_shuliang-invoke"] = "输粮：你可以移去一张“粮”，令 %dest 摸两张牌",
  ["ty_tunchu"] = "屯储",
  ["$tyta_tunchu1"] = "屯粮事大，暂不与尔等计较。",
  ["$tyta_tunchu2"] = "屯粮待战，莫动刀枪。",
  ["$tyta_shuliang1"] = "将军驰劳，酒肉慰劳。",
  ["$tyta_shuliang2"] = "将军，牌来了。",
  ["~tyta_heg__lifeng"] = "吾，有负丞相重托。",
}

local lingcao = General(extension, "tyta_heg__lingcao", "wu", 4)--凌操
local dujin = fk.CreateTriggerSkill{
 name ="tyta_dujin",
 anim_type = "drawcard",
 events = {fk.DrawNCards,fk.GeneralRevealed},
 can_trigger = function (self, event, target, player, data)
  if target ~= player or not player:hasSkill(self) then return false end
  if event == fk.GeneralRevealed then
    if player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player and H.getKingdomPlayersNum(player.room)[H.getKingdom(player)] == 1 then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    end
  else
    return  #player:getCardIds(Player.Equip) > 0
  end
end,
 on_use = function(self, event, target, player, data)
  if event == fk.GeneralRevealed  then
    H.addHegMark(player.room, player, "vanguard")
    ZR.addHegMark(player, 1, ZR.Vanguard)
  else
    data.n = data.n + math.ceil(#player:getCardIds(Player.Equip) / 2) 
  end
      end,
}
lingcao:addSkill(dujin)
Fk:loadTranslationTable{
 ["tyta_heg__lingcao"]= "凌操",
 ["#tyta_heg__lingcao"] = "激流勇进",
  ["illustrator:tyta_heg__lingcao"] = "樱花闪乱",
 ["tyta_dujin"]="独进",
 [":tyta_dujin"]="摸牌阶段，你可以多摸X张牌（X为你装备区牌数的一半，向上取整）。当你首次明置时，若场上没有与你势力相同的角色，你获得一个“先驱”标记。",
 ["#dujin_reveral"]="独进",
 ["$tyta_dujin1"] = "带兵十万，不如老夫多甲一件！",
 ["$tyta_dujin2"] = "轻舟独进，破敌先锋！",
 ["~tyta_heg__lingcao"] = "呃啊！（扑通）此箭……何来……",
}

local zhujun = General(extension,"tyta_heg__zhujun","qun",4)--朱儁
local gongjian = fk.CreateTriggerSkill{
  name = "tyta_gongjian",
  anim_type = "control",
  events = {fk.AfterCardsMove, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do 
        if move.moveReason == fk.ReasonDiscard and move.proposer == player.id and move.from ~= player.id then
          local cids = {}
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "slash" then
              table.insertIfNeed(cids, info.cardId)
            end
          end
          if #cids > 0 then
            self.cost_data = cids
            player.room:delay(500)
            return true
          end
        end
      end
      return
    else
      if data.card and player:hasSkill(self) and player:getMark("tyta_gongjian_record") ~= 0 and player:usedSkillTimes(self.name) == 0  then
        if data.card.trueName == "slash" and player:getMark("tyta_gongjian_used-turn") == 0 then
          local room = player.room
          local targets = U.getActualUseTargets(room, data, event) or {}
          local records = player:getMark("tyta_gongjian_record")
          if #targets == 0 then return end
          for _, id in ipairs(targets) do
            table.removeOne(records, id)
          end
          if #records == 0 then
            return true
          end
        end
      end
    end
    return
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return player.room:askForSkillInvoke(player, self.name, nil, "#tyta_gongjian-discard")
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#tyta_gongjian-ask")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      local cids = self.cost_data
      room:obtainCard(player, cids, true, fk.ReasonPrey)
    else
      local targets = U.getActualUseTargets(room, data, event)
      for _, id in ipairs(targets) do
        local p = room:getPlayerById(id)
        local cids =player.room:askForDiscard(p, 2, 2, true, self.name,false,nil,"#tyta_gongjian-discards")
      end
    end
  end,
  refresh_events = {fk.TargetConfirmed},
  can_refresh = function(self, event, target, player, data)
    if data.card and player:hasSkill(self, true, true) then
      return data.card.trueName == "slash" and #U.getActualUseTargets(player.room, data, event) > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "tyta_gongjian_record", U.getActualUseTargets(player.room, data, event))
  end,
}
local kuimang = fk.CreateTriggerSkill{
  name = "tyta_kuimang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
     return not H.compareKingdomWith(target, player) and player:hasSkill(self) and H.compareKingdomWith(data.damage.from,player) and player:usedSkillTimes(self.name) == 0
     and (H.inFormationRelation(player,data.damage.from) or (data.damage.from == player)) and not data.damage.from.dead
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}
zhujun:addSkill(gongjian)
zhujun:addSkill(kuimang)

Fk:loadTranslationTable{
  ["tyta_heg__zhujun"] = "朱儁",
  ["#tyta_heg__zhujun"] = "镇贼保国",
  ["tyta_gongjian"] = "攻坚",
  [":tyta_gongjian"] = "你弃置其他角色的牌或你令其他角色弃置的牌进入弃牌堆时，你可以获得其中的【杀】。每回合限一次，一名角色使用【杀】指定目标后，若目标角色均与本局游戏使用"..
  "的上一张【杀】相同，你可令目标角色弃置两张牌。",
  ["#tyta_gongjian-ask"] = "攻坚：你可以令此【杀】的目标弃置两张牌",
  ["#tyta_gongjian-discard"]="攻坚：你可以获得其中的【杀】",
  ["#tyta_gongjian-discards"]="攻坚：弃置两张牌",
  ["tyta_kuimang"] = "溃蟒",
  [":tyta_kuimang"] = "锁定技，每回合限一次，当你或与你处于同一队列的其他角色杀死一名与你势力不同的角色时，你摸两张牌。",
  ["$tyta_gongjian1"] = "善攻者，敌不知其守。",
  ["$tyta_gongjian2"] = "围解自出，势必意散。",
  ["$tyta_kuimang1"] = "黄巾流寇，不过如此。",
  ["$tyta_kuimang2"] = "黄巾作乱，奉旨平叛！",
  ["~tyta_heg__zhujun"] = "乞降不受，愿一战！",
}

local wangji = General(extension,"tyta_heg__wangji","wei",3)
local qizhi = fk.CreateTriggerSkill{
  name = "tyta_qizhi",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive and player:usedSkillTimes(self.name) ~= 3 and
      data.firstTarget and data.card.type ~= Card.TypeEquip
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p)
      return not p:isNude() and not table.contains(AimGroup:getAllTargets(data.tos), p.id) end), Util.IdMapper)
    if #targets == 0 then return end
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#tyqizhi-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@tyqizhi-turn", 1)
    local to = room:getPlayerById(self.cost_data.tos[1])
    local id = room:askForCardChosen(player, to, "he", self.name)
    room:throwCard({id}, self.name, to, player)
    if not to.dead then
      to:drawCards(1, self.name)
    end
  end,
}
local jinqu = fk.CreateTriggerSkill{
  name = "tyta_jinqu",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
    local n = #player:getCardIds("h") - player:usedSkillTimes("tyta_qizhi", Player.HistoryTurn)
    if n > 0 then
      player.room:askForDiscard(player, n, n, false, self.name, false)
    end
  end,
}
wangji:addSkill(qizhi)
wangji:addSkill(jinqu)
Fk:loadTranslationTable{
  ["tyta_heg__wangji"] = "王基",
  ["#tyta_heg__wangji"] = "经行合一",
  ["illustrator:tyta_heg__wangji"] = "雪君S",
  ["designer:tyta_heg__wangji"] = "韩旭",

  ["tyta_qizhi"] = "奇制",
  [":tyta_qizhi"] = "出牌阶段限三次，当你使用非装备牌指定目标后，你可以弃置一名不为目标的角色的一张牌，然后令其摸一张牌。",

  ["@tyqizhi-turn"] = "奇制",
  ["#tyqizhi-choose"] = "奇制：你可以弃置一名角色一张牌，然后其摸一张牌",
  
  ["tyta_jinqu"] = "进趋",
  [":tyta_jinqu"] = "结束阶段，你可以摸两张牌，然后将手牌弃至X张（X为你本回合发动〖奇制〗的次数）。",

  ["$tyta_qizhi1"] = "声东击西，敌寇一网成擒。",
  ["$tyta_qizhi2"] = "吾意不在此地，已遣别部出发。",
  ["$tyta_jinqu1"] = "建上昶水城，以逼夏口！",
  ["$tyta_jinqu2"] = "通川聚粮，伐吴之业，当步步为营。",
  ["~tyta_heg__wangji"] = "天下之势，必归大魏，可恨，未能得见呐！",
}

local yanyan = General(extension,"tyta_heg__yanyan","shu",4)
local juzhan = fk.CreateTriggerSkill{
  name = "tyta_juzhan",
  anim_type = "drawcard",
  events = {fk.TargetSpecified , fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then
      return false
    end
    if event == fk.TargetSpecified then  --使用杀时候
      return target == player and data.card.trueName == "slash" and
      player:usedSkillTimes(self.name, Player.HistoryGame) % 2 ~= 0 
      and not player.dead--奇数
      else
    return data.to == player.id and data.card.trueName == "slash" and player:usedSkillTimes(self.name, Player.HistoryGame) % 2 == 0 
      and data.from ~= player.id  --偶数
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      self.cost_data = {tos = {data.from}}
    else
      self.cost_data = {tos = {data.to}}
    end
    return player.room:askForSkillInvoke(player, self.name, nil)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local aim = data ---@type AimStruct
    if event == fk.TargetConfirmed then --被杀时
      room:addPlayerMark(player,"@tyta_juzhannums",1)
      local from = room:getPlayerById(aim.from)
      room:doIndicate(player.id, {from.id})
       player:drawCards(1,self.name)
       from:drawCards(1,self.name)
       if H.getGeneralsRevealedNum(from) == 2 and room:askForChoice(player, {"tyta_juzhan_hide::" .. from.id, "Cancel"}, self.name) ~= "Cancel" then
        for _, p in ipairs({from}) do
          local isDeputy = H.doHideGeneral(room, player, p, self.name)
          room:setPlayerMark(p, "@tyta_juzhan_reveal-turn", H.getActualGeneral(p, isDeputy))
          local record = type(p:getMark(MarkEnum.RevealProhibited .. "-turn")) == "table" and p:getMark(MarkEnum.RevealProhibited .. "-turn") or {}
          table.insert(record, isDeputy and "d" or "m")
          room:setPlayerMark(p, MarkEnum.RevealProhibited .. "-turn", record)
        end
        end
      else
        room:addPlayerMark(player,"@tyta_juzhannums",1)
        local to = room:getPlayerById(aim.to)
        room:doIndicate(player.id, {to.id})
        if not to:isKongcheng() then
        local card = room:askForCardChosen(player,to,"he",self.name,"#tyta_juzhan_chosencard")
        room:obtainCard(player.id,card,false,fk.ReasonPrey)
        if not player.dead then
        local x = player:getMark("@@tyta_juzhan-turn")
        if x == 0 then x = {} end
        table.insert(x, to.id)
        room:setPlayerMark(player, "@@tyta_juzhan-turn", x)
        room:setPlayerMark(to, "@@tyta_juzhan-prohibit-turn", x)
        end
      end
    end
  end,
}
local juzhan_prohibit = fk.CreateProhibitSkill{
  name = "#tyta_juzhan_prohibit",
  is_prohibited = function(self, player, to)
    local x = player:getMark("@@tyta_juzhan-turn")
    if x == 0 then return false end
    return table.contains(x, to.id)
  end,
}
juzhan:addRelatedSkill(juzhan_prohibit)
yanyan:addSkill(juzhan)

Fk:loadTranslationTable{
  ["tyta_heg__yanyan"] = "严颜",
  ["#tyta_heg__yanyan"] = "断头将军",
  ["illustrator:tyta_heg__yanyan"] = "Town",

  ["tyta_juzhan"] = "拒战",
  [":tyta_juzhan"] = "当你成为【杀】的目标后，若你发动过此技能的次数为偶数，你可以与使用者各摸一张牌，然后若其武将牌均明置，你可以暗置其一张武将牌，本回合不能再明置。"..
  "当你使用【杀】指定目标后，若你发动过此技能的次数为奇数，你可以获得其一张牌，然后你本回合不能对其使用牌。",
 
  ["#tyta_juzhan-ask"] = "你想对 %dest 发动 “拒战” 吗？",
  ["tyta_juzhan_hide"] = "暗置%dest一张武将牌且本回合不能明置",
  ["@@tyta_juzhan-turn"] = "拒战",
  ["@tyta_juzhannums"] = "拒战次数",
  ["@@tyta_juzhan-prohibit-turn"] = "不能成为目标",
  ["@tyta_juzhan_reveal-turn"] = "拒战禁亮",
  ["#tyta_juzhan_chosencard"] = "拒战:选择一张牌获得之",

  ["~tyta_heg__yanyan"] = "宁可断头死，安能屈膝降！",
  ["$tyta_juzhan1"] = "砍头便砍头，何为怒耶！",
  ["$tyta_juzhan2"] = "我州但有断头将军，无降将军也！",
}

local zhuran = General(extension,"tyta_heg__zhuran","wu",4)
local danshou = fk.CreateTriggerSkill{
  name= "tyta_danshou",
  anim_type = "drawcard",
  events = {fk.TurnStart, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
  if event == fk.TurnStart then
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 
 else
  if player:hasSkill(self) and player:getMark("@tyta__danshou_enable-turn") > 0 and 
       target.phase > Player.Start and target.phase < Player.Finish then
        return #player:getCardIds(Player.Hand) <= player:getMark("@tyta__danshou_enable-turn")
     end
   end
end,
on_cost = function(self, event, target, player, data)
  if event == fk.TurnStart then
    return player.room:askForSkillInvoke(player, self.name, nil, "#tyta__danshou-ask:"..target.id)
  else
    if player.room:askForSkillInvoke(player, self.name, nil, "#tyta__danshou-choose:::"..player:getMark("@tyta__danshou_record-turn")) then
      self.cost_data = 1
    else
      self.cost_data = 2
    end
    return true
  end
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  if event == fk.TurnStart then
    room:setPlayerMark(player, "@tyta__danshou_record-turn", 1)
    local cids = player:getCardIds("hej") or {}
    player:throwAllCards("hej")
    room:setPlayerMark(player, "@tyta__danshou_enable-turn", #cids)
  else
    if self.cost_data == 1 then
      player:drawCards(player:getMark("@tyta__danshou_record-turn"), self.name)
      if not player.dead and room.current and not (room.current or {}).dead and player:getMark("@tyta__danshou_record-turn") >= 4 then
        if player.room:askForSkillInvoke(player, self.name, nil, "#tyta__danshou-damage:"..room.current.id) then
          room:doIndicate(player.id, { room.current.id })
          room:damage {
            from = player, 
            to = room.current,
            damage = 1, 
            skillName = self.name, 
            damageType = fk.NormalDamage,
          }
        end
      end
    else
      room:addPlayerMark(player, "@tyta__danshou_record-turn", 1)
    end
  end
end,
}
zhuran:addSkill(danshou)
Fk:loadTranslationTable{
  ["tyta_heg__zhuran"] = "朱然",
  ["#tyta_heg__zhuran"] = "不动之督",
  ["illustrator:tyta_heg__zhuran"] = "F源",
  ["tyta_danshou"] = "胆守",
  [":tyta_danshou"] = "每轮限一次，一名角色回合开始时，你可以弃置你区域内的所有牌，然后你于本回合每个阶段（准备阶段和结束阶段除外）开始时："..
  "若你的手牌数不大于X（X为你此次弃置的牌数），你摸一张牌或令你本回合“胆守”的摸牌数+1；当你一次性以此法摸四张牌后，你可以对当前回合角色造成1点伤害。",
  ["@tyta__danshou_enable-turn"] = "胆守弃置",
  ["@tyta__danshou_record-turn"] = "胆守摸牌",
  ["#tyta__danshou-ask"] = "你可以于 %src 回合发动“胆守”",
  ["#tyta__danshou-choose"] = "胆守：你可以摸 %arg 张牌，或点击取消令你本回合“胆守”的摸牌数+1",
  ["#tyta__danshou-damage"] = "胆守：你可以对 %src 造成1点伤害",

  ["$tyta_danshou1"] = "此城危难，我必当竭尽全力！",
  ["$tyta_danshou2"] = "大丈夫屈伸有道，不在一时胜负。",
  ["~tyta_heg__zhuran"] = "大耳贼就在眼前，快追……",
}



local xurong = General(extension,"tyta_heg__xurong","qun",4)
local xionghuo = fk.CreateActiveSkill{
  name = "tyta_xionghuo",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#tyxionghuo-active",
  can_use = function(self, player)
    return player:getMark("@hegbaoli") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("@hegbaoli") == 0
    and (Fk:currentRoom():getPlayerById(to_select).kingdom ~= Self.kingdom or Fk:currentRoom():getPlayerById(to_select).kingdom == "wild") and
    (Fk:currentRoom():getPlayerById(to_select).general ~= "anjiang" or Fk:currentRoom():getPlayerById(to_select).deputyGeneral ~= "anjiang" )
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:removePlayerMark(player, "@hegbaoli", 1)
    room:addPlayerMark(target, "@hegbaoli", 1)
  end,
}
local xionghuo_record = fk.CreateTriggerSkill{
  name = "#tyta_xionghuo_record",
  main_skill = xionghuo,
  anim_type = "offensive",
  events = {fk.GeneralRevealed, fk.DamageCaused, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(xionghuo) then
      if event == fk.GeneralRevealed then
        return player:getMark("@hegbaoli") < 3 and player:usedSkillTimes("tyta_xionghuo", Player.HistoryGame) == 0
        and target == player and H.hasShownSkill(player,"tyta_xionghuo") --首次明置
      elseif event == fk.DamageCaused then
        return target == player and data.to ~= player and data.to:getMark("@hegbaoli") > 0 and
         data.to:getMark("tyta_xionghuo_damaged-turn") ~= 1 --每回合加伤一次
      else
        return target ~= player and target:getMark("@hegbaoli") > 0 and target.phase == Player.Play
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("tyta_xionghuo")
    if event == fk.GeneralRevealed then
      room:setPlayerMark(player, "@hegbaoli", 3)
    elseif event == fk.DamageCaused then
      room:doIndicate(player.id, {data.to.id})
      data.damage = data.damage + 1
      room:setPlayerMark(data.to,"tyta_xionghuo_damaged-turn",1)
    else
      room:doIndicate(player.id, {target.id})
      room:removePlayerMark(target, "@hegbaoli", 1)
      local rand = math.random(1, target:isNude() and 2 or 3)
      if rand == 1 then
        room:damage {
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = "tyta_xionghuo",
        }
        room:addTableMark(target, "tyta_xionghuo_prohibit-turn", player.id)
      elseif rand == 2 then
        room:loseHp(target, 1, "tyta_xionghuo")
      else
        local num = #target:getCardIds(Player.Equip)
        if num ~= 0 then
        local cards = room:askForCardChosen(player, target, "e", self.name)
        room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, "tyta_xionghuo", "", false, player.id)
        end
        local num2 = #target:getCardIds(Player.Hand)
        if num2 ~= 0 then
        local cards1 = room:askForCardChosen(player, target, "h", self.name)
        room:moveCardTo(cards1, Player.Hand, player, fk.ReasonPrey, "tyta_xionghuo", "", false, player.id)
      end
      end
    end
  end,
}
local xionghuo_prohibit = fk.CreateProhibitSkill{
  name = "#tyta_xionghuo_prohibit",
  is_prohibited = function(self, from, to, card)
    return card.trueName == "slash" and table.contains(from:getTableMark( "tyta_xionghuo_prohibit-turn") ,to.id)
  end,
}
xionghuo:addRelatedSkill(xionghuo_record)
xionghuo:addRelatedSkill(xionghuo_prohibit)
xurong:addSkill(xionghuo)
Fk:loadTranslationTable{
  ["tyta_heg__xurong"] = "徐荣",
  ["#tyta_heg__xurong"] = "玄菟战魔",
  ["cv:tyta_heg__xurong"] = "曹真",
  ["designer:tyta_heg__xurong"] = "Loun老萌",
  ["illustrator:tyta_heg__xurong"] = "zoo",
  ["tyta_xionghuo"] = "凶镬",
  [":tyta_xionghuo"] = "当你首次明置此武将牌时，你获得3个“暴戾”标记。出牌阶段，你可以令一名没有“暴戾”标记的与你势力不同的角色获得你的1枚“暴戾”标记；"..
  "每回合对每名角色限一次，你对有此标记的其他角色造成的伤害+1。有“暴戾”的其他角色出牌阶段开始时，移去“暴戾”标记并随机执行一项："..
  "1.受到你造成的1点火焰伤害且本回合不能对你使用【杀】；"..
  "2.失去1点体力且本回合手牌上限-1；"..
  "3.你依次获得其装备区和手牌内的各一张牌。",
  ["#tyta_xionghuo_record"] = "凶镬",
  ["@hegbaoli"] = "暴戾",
  ["#tyxionghuo-active"] = "发动 凶镬，将“暴戾”交给其他角色",

  ["$tyta_xionghuo1"] = "此镬加之于你，定有所伤！",
  ["$tyta_xionghuo2"] = "凶镬沿袭，怎会轻易无伤？",
  ["~tyta_heg__xurong"] = "此生无悔，心中无愧。",
}
  return extension